function findKpandhks($scope, CertusFormAjax, CertusJsonAjax) {
// 开票信息
    var plistColumns = [{
        id: 'pro_name',
        title: '所属项目',
        type: 'string',
        columnClass: 'text-center',
    },{
        id: 'contract_id',
        title: '合同编号',
        width: 150,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'invoiceBuget',
        title: '开票金额',
        width: 150,
        type: 'string',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'user_name',
        title: '开票人',
        width: 75,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'invoice_time',
        title: '开票时间',
        width: 100,
        type: 'date',
        format:'yyyy-MM-dd',
        otype:'time_stamp_ms',
        columnClass: 'text-center',
    }, {
        id: 'invoice_comments',
        title: '发票内容',
        type: 'string',
        columnClass: 'text-left',
    }, {
        id: 'invoice_sl',
        title: '税率',
        width: 60,
        type: 'string',
        columnClass: 'text-center',
        resolution: function (value, record) {
            return record.invoice_sl+"%";
        }
    }, {
        id: 'operation',
        title: '操作',
        type: 'string',
        width: 60,
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '无';
            //计算相差多少天
            var d = new Date();
            start = record.createTime.replace(/-/g, "/");
            var startdate = new Date(start);
            var time = d.getTime() - startdate.getTime();
            var days = parseInt(time / (1000 * 60 * 60 * 24));
            //大于三天则不能修改和删除
            if (days <= 1) {
                content = '<button class="btn btn-xs btn-danger" onclick="delInvoice(' + record.id + ');"><i class="fa fa-trash-o"></i>  删除</button>';
            }
            // content += '<button class="btn btn-xs btn-success" onclick="edpc(' + record.id + ');"><i class="icon-edit"></i>  编辑</button>';
            // content += '  ';
            return content;
        }
    }];
    this.searchInvos = function (param) {
        $("#plistContainer").html("");
        $("#plistToolContainer").html("");
        CertusFormAjax.ajax("findAllInvos",{"param":param},function (response) {
            var plistOption = {
                lang: 'zh-cn',
                ajaxLoad: false,
                extraWidth: 20,
                // loadURL:'url',
                exportFileName: '开票信息',
                datas: response.data,
                columns: plistColumns,
                gridContainer: 'plistContainer',
                toolbarContainer: 'plistToolContainer',
                tools: '',
                pageSize: 10,
                pageSizeLimit: [10, 15, 20]
            };
            var plistGrid = $.fn.dlshouwen.grid.init(plistOption);
            plistGrid.load();
        });

        //已删除开票信息
        var delkpColumns = [{
            id: 'pro_name',
            title: '所属项目',
            width: 150,
            type: 'string',
            columnClass: 'text-center',
        },{
            id: 'contract_id',
            title: '合同编号',
            width: 150,
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'invoice_buget',
            title: '开票金额',
            width: 80,
            type: 'string',
            columnClass: 'text-center',
            resolution: function (value, record, column, grid, dataNo, columnNo) {
                if (value==""){
                    value=0;
                }
                var content = '￥' + value + '元';
                return content;
            }
        }, {
            id: 'user_name',
            title: '开票人',
            width: 80,
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'invoice_time',
            title: '开票时间',
            width: 100,
            type: 'date',
            format:'yyyy-MM-dd',
            otype:'time_stamp_ms',
            columnClass: 'text-center',
        }, {
            id: 'invoice_comments',
            title: '发票内容',
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'invoice_sl',
            title: '税率',
            width: 60,
            type: 'string',
            columnClass: 'text-center',
            resolution: function (value, record) {
                return record.invoiceSl+"%";
            }
        }, {
            id: 'del_time',
            title: '删除时间',
            width: 100,
            type: 'date',
            format:'yyyy-MM-dd',
            otype:'time_stamp_ms',
            columnClass: 'text-center'
        }, {
            id: 'del_user_name',
            title: '删除人',
            width: 80,
            type: 'string',
            columnClass: 'text-center'
        }];
        $("#delkpContainer").html("");
        $("#delkpToolContainer").html("");
        CertusFormAjax.ajax("findAllDelInvos", { "param": param }, function (response) {
            var recaOption = {
                lang: 'zh-cn',
                ajaxLoad: false,
                extraWidth: 20,
                // loadURL:'url',
                exportFileName: '已删除验收记录',
                datas: response.data,
                columns: delkpColumns,
                gridContainer: 'delkpContainer',
                toolbarContainer: 'delkpToolContainer',
                tools: '',
                pageSize: 10,
                pageSizeLimit: [10, 15, 20]
            };
            var recaGrid = $.fn.dlshouwen.grid.init(recaOption);
            recaGrid.load();
        })
    }
    searchInvos("");
    // 回款信息
    var recbleColumns = [{
        id: 'pro_name',
        title: '所属项目',
        type: 'string',
        columnClass: 'text-center',
    },{
        id: 'contract_id',
        title: '合同编号',
        width: 150,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'user_name',
        title: '经办人',
        width: 75,
        type: 'string',
        columnClass: 'text-center',
    }, {
        id: 'paymentBuget',
        title: '回款金额',
        width: 150,
        type: 'string',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'payment_time',
        title: '回款日期',
        width: 100,
        columnClass: 'text-center',
        type: 'date',
        format:'yyyy-MM-dd',
        otype:'time_stamp_ms'
    }, {
        id: 'payment_comments',
        title: '回款说明',
        type: 'string',
        columnClass: 'text-left',
    },{
        id: 'create_time',
        title: '上传时间',
        width: 100,
        columnClass: 'text-center',
        type: 'date',
        format:'yyyy-MM-dd',
        otype:'time_stamp_ms'
    }, {
        id: 'operation',
        title: '操作',
        type: 'string',
        width: 60,
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '无';
            //计算相差多少天
            var d = new Date();
            start = record.createTime.replace(/-/g, "/");
            var startdate = new Date(start);
            var time = d.getTime() - startdate.getTime();
            var days = parseInt(time / (1000 * 60 * 60 * 24));
            //大于三天则不能修改和删除
            if (days <= 1) {
                content = '<button class="btn btn-xs btn-danger" onclick="delPaymet(' + record.id + ');"><i class="fa fa-trash-o"></i>  删除</button>';
            }
            // content += '<button class="btn btn-xs btn-success" onclick=""><i class="icon-edit"></i>  编辑</button>';
            // content += '  ';
            return content;
        }
    }];

    this.searchPayments = function (param) {
        $("#recbleContainer").html("");
        $("#recbleToolContainer").html("");
        CertusFormAjax.ajax("findAllPayments",{"param":param},function (response) {
            var recbleOption = {
                lang: 'zh-cn',
                ajaxLoad: false,
                extraWidth: 20,
                // loadURL:'url',
                exportFileName: '回款信息列表',
                datas: response.data,
                columns: recbleColumns,
                gridContainer: 'recbleContainer',
                toolbarContainer: 'recbleToolContainer',
                tools: '',
                pageSize: 10,
                pageSizeLimit: [10, 15, 20]
            };
            var recbleGrid = $.fn.dlshouwen.grid.init(recbleOption);
            recbleGrid.load();
        });

        var delhkColumns = [{
            id: 'pro_name',
            title: '所属项目',
            type: 'string',
            columnClass: 'text-center',
        },{
            id: 'contract_id',
            title: '合同编号',
            width: 150,
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'user_name',
            title: '经办人',
            width: 75,
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'paymentBuget',
            title: '回款金额',
            width: 150,
            type: 'string',
            columnClass: 'text-center',
            resolution: function (value, record, column, grid, dataNo, columnNo) {
                if (value==""){
                    value=0;
                }
                var content = '￥' + value + '元';
                return content;
            }
        }, {
            id: 'payment_time',
            title: '回款日期',
            width: 100,
            columnClass: 'text-center',
            type: 'date',
            format:'yyyy-MM-dd',
            otype:'time_stamp_ms'
        }, {
            id: 'payment_comments',
            title: '回款说明',
            type: 'string',
            columnClass: 'text-left',
        },{
            id: 'del_time',
            title: '删除时间',
            width: 100,
            columnClass: 'text-center',
            type: 'date',
            format:'yyyy-MM-dd',
            otype:'time_stamp_ms'
        }, {
            id: 'del_user_name',
            title: '删除人',
            type: 'string',
            columnClass: 'text-center',
        }];
        $("#delhkContainer").html("");
        $("#delhkToolContainer").html("");
        CertusFormAjax.ajax("findAllDelPayments",{"param":param},function (response) {
            var recbleOption = {
                lang: 'zh-cn',
                ajaxLoad: false,
                extraWidth: 20,
                // loadURL:'url',
                exportFileName: '已删除回款信息列表',
                datas: response.data,
                columns: delhkColumns,
                gridContainer: 'delhkContainer',
                toolbarContainer: 'delhkToolContainer',
                tools: '',
                pageSize: 10,
                pageSizeLimit: [10, 15, 20]
            };
            var recbleGrid = $.fn.dlshouwen.grid.init(recbleOption);
            recbleGrid.load();
        });
    };
    searchPayments("");
    // 合同信息-统计数据
    var hlistColumns = [{
        id: 'proName',
        title: '所属项目',
        type: 'string',
        columnClass: 'text-center',
    },{
        id: 'contractNo',
        title: '合同编号',
        type: 'string',
        width: 150,
        columnClass: 'text-center',
    }, {
        id: 'contractAmout',
        title: '合同金额',
        width: 150,
        type: 'string',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'invoiceBuget',
        title: '开票总金额',
        width: 150,
        type: 'string',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            if (value==""){
                value=0;
            }
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'syKpBuget',
        title: '剩余开票金额',
        width: 150,
        type: 'string',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            if (value==""){
                value=0;
            }
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'paymentBuget',
        title: '已收款',
        width: 150,
        type: 'string',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            if (value==""){
                value=0;
            }
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'sypmBuget',
        title: '未收款',
        width: 150,
        type: 'string',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            if (value==""){
                value=0;
            }
            var content = '￥' + value + '元';
            return content;
          }
    }];
    // {
    //     id: 'operation',
    //         title: '操作',
    //     type: 'string',
    //     width: 60,
    //     columnClass: 'text-center',
    //     resolution: function (value, record, column, grid, dataNo, columnNo) {
    //     var content = '';
    //     content += '<button class="btn btn-xs btn-primary" onclick=""><i class="icon-eye-open"></i>  查看</button>';
    //     // content += '  ';
    //     // content += '<button class="btn btn-xs btn-danger" onclick="down(' + record.id + ');"><i class="fa fa-trash-o"></i>  删除</button>';
    //     return content;
    // }
    // }
    this.searhTjInfo = function (param) {
        $("#hlistContainer").html("");
        $("#hlistToolContainer").html("");
        CertusFormAjax.ajax("findAllBugetTjInfo",{"param":param},function (response) {
            var hlistOption = {
                lang: 'zh-cn',
                ajaxLoad: false,
                extraWidth: 20,
                // loadURL:'url',
                exportFileName: '合同信息-统计数据',
                datas: response.data,
                columns: hlistColumns,
                gridContainer: 'hlistContainer',
                toolbarContainer: 'hlistToolContainer',
                tools: '',
                pageSize: 10,
                pageSizeLimit: [10, 15, 20]
            };
            var hlistGrid = $.fn.dlshouwen.grid.init(hlistOption);
            hlistGrid.load();
        });
    }
    searhTjInfo("");

    this.searchYsInfo = function (param) {
        // 初验报告
        var recaColumns = [{
            id: 'contract_id',
            title: '合同编号',
            width: 150,
            type: 'string',
            columnClass: 'text-center',
        },{
            id: 'acceptance_type',
            title: '类型',
            width: 80,
            type: 'string',
            columnClass: 'text-center',
        },{
            id: 'customer_name',
            title: '验收签字人',
            width: 90,
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'acceptanceTime',
            title: '验收日期',
            width: 120,
            type: 'string',
            columnClass: 'text-center'
        }, {
            id: 'acceptance_result',
            title: '验收结果',
            width: 100,
            type: 'string',
            format:'yyyy-MM-dd',
            otype:'time_stamp_ms',
            columnClass: 'text-center',
        }, {
            id: 'acceptance_comments',
            title: '验收结果说明',
            // width: 150,
            type: 'string',
            columnClass: 'text-left',
        }, {
            id: 'operation',
            title: '操作',
            type: 'string',
            width: 60,
            columnClass: 'text-center',
            resolution: function (value, record) {
                var content = '无';
                //计算相差多少天
                var d = new Date();
                start = record.createTime.replace(/-/g, "/");
                var startdate = new Date(start);
                var time = d.getTime() - startdate.getTime();
                var days = parseInt(time / (1000 * 60 * 60 * 24));
                //大于三天则不能修改和删除
                if (days <= 1) {
                    content = '<button class="btn btn-xs btn-danger" onclick="delYs(' + record.id + ');"><i class="fa fa-trash-o"></i>  删除</button>';
                }
                return content;
            }
        }];
        $("#ysContainer").html("");
        $("#ysToolContainer").html("");
        CertusFormAjax.ajax("findAllAcceptance",{"param":param},function (response) {
            var recaOption = {
                lang: 'zh-cn',
                ajaxLoad: false,
                extraWidth: 20,
                // loadURL:'url',
                exportFileName: '验收信息列表',
                datas: response.data,
                columns: recaColumns,
                gridContainer: 'ysContainer',
                toolbarContainer: 'ysToolContainer',
                tools: '',
                pageSize: 10,
                pageSizeLimit: [10, 15, 20]
            };
            var recaGrid = $.fn.dlshouwen.grid.init(recaOption);
            recaGrid.load();
        });

        //已删除验收信息
        var delysColumns = [{
            id: 'contract_id',
            title: '合同编号',
            width: 150,
            type: 'string',
            columnClass: 'text-center',
        },{
            id: 'acceptance_type',
            title: '类型',
            width: 80,
            type: 'string',
            columnClass: 'text-center',
        },{
            id: 'customer_name',
            title: '验收签字人',
            width: 90,
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'acceptanceTime',
            title: '验收日期',
            width: 120,
            type: 'string',
            columnClass: 'text-center'
        }, {
            id: 'acceptance_result',
            title: '验收结果',
            width: 100,
            type: 'string',
            columnClass: 'text-center',
        }, {
            id: 'del_time',
            title: '删除日期',
            width: 120,
            type: 'date',
            format:'yyyy-MM-dd',
            otype:'time_stamp_ms',
            columnClass: 'text-center'
        },{
            id: 'del_user_name',
            title: '删除人',
            width: 80,
            type: 'string',
            columnClass: 'text-center',
        }];
        $("#ysDelContainer").html("");
        $("#ysDelToolContainer").html("");
        CertusFormAjax.ajax("findAllDelAcceptance",{"param":param},function (response) {
            var recaOption = {
                lang: 'zh-cn',
                ajaxLoad: false,
                extraWidth: 20,
                // loadURL:'url',
                exportFileName: '已删除验收信息列表',
                datas: response.data,
                columns: delysColumns,
                gridContainer: 'ysDelContainer',
                toolbarContainer: 'ysDelToolContainer',
                tools: '',
                pageSize: 10,
                pageSizeLimit: [10, 15, 20]
            };
            var recaGrid = $.fn.dlshouwen.grid.init(recaOption);
            recaGrid.load();
        });
    };
    searchYsInfo("");
    $(".ybsubmit").on('click',function () {
        searhTjInfo($("#prcType").val());
        searchPayments($("#prcType").val());
        searchInvos($("#prcType").val());
        searchYsInfo($("#prcType").val());
    })
    this.delInvoice = function (id) {
        layer.confirm('确认删除此数据？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            CertusFormAjax.ajax("delInvoice",{"id":id},function (response) {
                layer.msg("删除成功");
                window.location.reload();
            });
        });
    };

    this.delPaymet = function (id) {
        layer.confirm('确认删除此数据？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            CertusFormAjax.ajax("delPaymet",{"id":id},function (response) {
                layer.msg("删除成功");
                window.location.reload();
            });
        })
    };
    this.delYs = function (id) {
        layer.confirm('确认删除此数据？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            CertusFormAjax.ajax("delAccps",{"id":id},function () {
                layer.msg("删除成功");
                window.location.reload();
            });
        })
    }
}
function addKpandhks($scope, CertusFormAjax) {
    CertusFormAjax.ajax("findSpUserList",{},function (response) {
        var nhlTeams = [];
        var data = response.data;
        for (var i=0;i<data.length;i++){
            var arr={};
            arr.name=data[i].userName+"["+data[i].positonName+"]";
            arr.id = data[i].userId;
            nhlTeams.push(arr);
        }
        //自动补全
        var nhl = $.map(nhlTeams, function (obj) {
            return {
                value: obj.name,
                data: { category: obj.id }
            };
        });
        // Initialize autocomplete with local lookup:
        $('#autocomplete').devbridgeAutocomplete({
            lookup: nhl,
            minChars: 1,
            onSelect: function (suggestion) {
                $("#invoiceUserId").val(suggestion.data.category);
            },
            showNoSuggestionNotice: true,
            noSuggestionNotice: 'Sorry, no matching results'
        });
    });
    this.getProContract = function () {
        CertusFormAjax.ajax("contractProgresss",{"projId":$("#proId").val()},function (response) {
            var data = response.data;
            $("#contractId").html("");
            $("#contractId").append('<option value="">请选择</option>');
            for (var i=0;i<data.length;i++){
                var ctinfo = data[i].contractInfo;
                $("#contractId").append("<option value='"+ctinfo.contractNo+"'>"+ctinfo.contractNo+"</option>")
            }
        });
    }
    CertusFormAjax.ajax("findSeProList",{},function(response){
        var nhlTeams = [];
        var data = response.data;
        for (var i=0;i<data.length;i++){
            var arr={};
            arr.name=data[i].proName;
            arr.id = data[i].id;
            nhlTeams.push(arr);
        }
        //自动补全
        var nhl = $.map(nhlTeams, function (obj) {
            return {
                value: obj.name,
                data: { category: obj.id }
            };
        });
        // Initialize autocomplete with local lookup:
        $('#proName').devbridgeAutocomplete({
            lookup: nhl,
            minChars: 1,
            onSelect: function (suggestion) {
                $("#proId").val(suggestion.data.category);
                getProContract();
                getSyMoney(suggestion.data.category);
            },
            showNoSuggestionNotice: true,
            noSuggestionNotice: 'Sorry, no matching results'
        });
    });

    var contractArr = [];
    this.getSyMoney = function (proId) {
        CertusFormAjax.ajax("contractProgresss",{"projId":proId},function (response) {
            var data = response.data;
            var html="";
            for (var i=0;i<data.length;i++){
                var arr={};
                arr.contractNo = data[i].contractInfo.contractNo;
                arr.contractAmount = data[i].contractInfo.contractAmount;
                arr.kpTotalMoney = data[i].kpTotalMoney;
                var ctinfo = data[i].contractInfo;
                $("#contractId").append("<option value='"+ctinfo.contractNo+"'>"+ctinfo.contractNo+"</option>");
                contractArr.push(arr);
            }
        });
    };

    var htMoney = 0;
    this.getAmoutMoney = function (contractNo) {
        if (contractNo==""){
            $("#invoiceBuget").attr("placeholder","具体金额");
        }else{
            for (var i = 0;i<contractArr.length;i++){
                if (contractNo == contractArr[i].contractNo){
                    htMoney = contractArr[i].contractAmount-contractArr[i].kpTotalMoney;
                    if (htMoney<0){
                        htMoney=0;
                    }
                    $("#invoiceBuget").attr("placeholder","未开票金额:"+Number(htMoney).toFixed(2));
                }
            }
        }
    };

    $(".submit").on('click',function () {
        if (!certusValidateNotnull()){
            return;
        }

        if ($("#invoiceBuget").val()==0){
            layer.msg("开票金额不能为0");
            return;
        }

        if (Number($("#invoiceBuget").val())>htMoney){
            layer.msg("开票金额不能超过未开票金额");
            return;
        }

        var data = new Date();
        var datetime = $("#invoiceTime").val();
        if (datetime!=""){
            var startTime = new Date(datetime.replace("/", "-").replace("/", "-"));
            if (startTime>data){
                // layer.msg("开票日期不能大于当前日期",{time:1000});
                // return;
            }
        }
        if ($("#invoiceComments").val().length>120){
            layer.msg("发票类容概述不能超过120字",{"time":1000});
            return;
        }

        var arr =$("form").serializeArray();
        var data = {};
        for (var i=0;i<arr.length;i++){
            data[arr[i].name] = arr[i].value;
        };
        CertusFormAjax.ajax("addInvoice",{"projId":$("#proId").val(),"param":JSON.stringify(data)},function (response) {
            layer.msg("添加成功",{"time":1000});
            window.history.back();
        })
    })
}
//--------------------------------------------------------
function addPayments($scope, CertusFormAjax) {
    this.getProContract = function () {
        CertusFormAjax.ajax("contractProgresss",{"projId":$("#proId").val()},function (response) {
            var data = response.data;
            var html="";
            for (var i=0;i<data.length;i++){
                var ctinfo = data[i].contractInfo;
                $("#contractId").append("<option value='"+ctinfo.contractNo+"'>"+ctinfo.contractNo+"</option>")
            }
        });
    }
    CertusFormAjax.ajax("findSeProList",{},function(response){
        var nhlTeams = [];
        var data = response.data;
        for (var i=0;i<data.length;i++){
            var arr={};
            arr.name=data[i].proName;
            arr.id = data[i].id;
            nhlTeams.push(arr);
        }
        //自动补全
        var nhl = $.map(nhlTeams, function (obj) {
            return {
                value: obj.name,
                data: { category: obj.id }
            };
        });
        // Initialize autocomplete with local lookup:
        $('#proName').devbridgeAutocomplete({
            lookup: nhl,
            minChars: 1,
            onSelect: function (suggestion) {
                $("#proId").val(suggestion.data.category);
                getProContract();
            },
            showNoSuggestionNotice: true,
            noSuggestionNotice: 'Sorry, no matching results'
        });
    });
    CertusFormAjax.ajax("findSpUserList",{},function (response) {
        var nhlTeams = [];
        var data = response.data;
        for (var i=0;i<data.length;i++){
            var arr={};
            arr.name=data[i].userName+"["+data[i].positonName+"]";
            arr.id = data[i].userId;
            nhlTeams.push(arr);
        }
        //自动补全
        var nhl = $.map(nhlTeams, function (obj) {
            return {
                value: obj.name,
                data: { category: obj.id }
            };
        });
        // Initialize autocomplete with local lookup:
        $('#autocomplete').devbridgeAutocomplete({
            lookup: nhl,
            minChars: 1,
            onSelect: function (suggestion) {
                $("#dearUserId").val(suggestion.data.category);
            },
            showNoSuggestionNotice: true,
            noSuggestionNotice: 'Sorry, no matching results'
        });
    });
    
    $(".psubmit").on('click',function () {
        if (!certusValidateNotnull()){
            return;
        }
        var data = new Date();
        var datetime = $("#paymentTime").val();
        if (datetime!=""){
            var startTime = new Date(datetime.replace("/", "-").replace("/", "-"));
            if (startTime>data){
                // layer.msg("回款日期不能大于当前日期",{time:1000});
                // return;
            }
        }

        if ($("#paymentComments").length>500){
            layer.msg("回款说明不能大于500字");
            return;
        }

        var arr =$("form").serializeArray();
        var data = {};
        for (var i=0;i<arr.length;i++){
            data[arr[i].name] = arr[i].value;
        };
        CertusFormAjax.ajax("addPayment",{"projId":$("#proId").val(),"param":JSON.stringify(data)},function (response) {
            layer.msg("添加成功",{"time":1000});
            window.history.back();
        });
    })

}


function toBack() {
    window.history.back();
}

function addHkinfo() {
    CertusFormAjax.ajax("findSpUserList",{},function (response) {
        var nhlTeams = [];
        var data = response.data;
        for (var i=0;i<data.length;i++){
            var arr={};
            arr.name=data[i].userName+"["+data[i].positonName+"]";
            arr.id = data[i].userId;
            nhlTeams.push(arr);
        }
        //自动补全
        var nhl = $.map(nhlTeams, function (obj) {
            return {
                value: obj.name,
                data: { category: obj.id }
            };
        });
        // Initialize autocomplete with local lookup:
        $('#autocomplete').devbridgeAutocomplete({
            lookup: nhl,
            minChars: 1,
            onSelect: function (suggestion) {
                $("#dearUserId").val(suggestion.data.category);
            },
            showNoSuggestionNotice: true,
            noSuggestionNotice: 'Sorry, no matching results'
        });
    });

    this.getProContract = function () {
        CertusFormAjax.ajax("contractProgresss",{"projId":$("#proId").val()},function (response) {
            var data = response.data;
            $("#contractId").html("");
            $("#contractId").append('<option value="">请选择</option>');
            for (var i=0;i<data.length;i++){
                var ctinfo = data[i].contractInfo;
                $("#contractId").append("<option value='"+ctinfo.contractNo+"'>"+ctinfo.contractNo+"</option>")
            }
        });
    }

    $(".psubmit").on('click',function () {
        if ($("#contractId").val()==""){
            layer.msg("请选择合同编号");
            return;
        }
        if ($("#paymentType").val()==""){
            layer.msg("请选择合同类型");
            return;
        }
        if ($("#dearUserId").val()==""){
            layer.msg("经办人不能为空");
            return;
        }
        if ($("#paymentBuget").val()==""){
            layer.msg("回款金额不能为空");
            return;
        }
        if ($("#paymentTime").val()==""){
            layer.msg("回款日期不能为空");
            return;
        }
        if ($("#paymentComments").length>500){
            layer.msg("回款说明不能大于500字");
            return;
        }
        if ($("#paymentComments").val()==""){
            layer.msg("回款说明不能为空");
            return;
        }

        var arr =$("form").serializeArray();
        var data = {};
        for (var i=0;i<arr.length;i++){
            data[arr[i].name] = arr[i].value;
        };
        data.proId = proId;
        CertusFormAjax.ajax("addPayment",{"projId":proId,"param":JSON.stringify(data)},function (response) {
            layer.msg("添加成功",{"time":1000});
            toLoadHtml(102);
        })
    })
}